<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "activity_lottery_prize".
 *
 * @property string $prize_id
 * @property string $activity_id
 * @property string $goods_id
 * @property string $cover_img
 * @property string $info
 * @property integer $num
 * @property integer $percentage
 * @property integer $max_num
 * @property string $instructions
 * @property integer $prize_type
 * @property string $general_id
 * @property integer $is_show
 * @property string $hidename
 * @property string $hidepic
 * @property string $hidehuiwenbi
 * @property string $create_time
 */
class ActivityLotteryPrize extends \yii\db\ActiveRecord
{
    public static function getDb()
    {
        return yii::$app->vrshop;
    }

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'activity_lottery_prize';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['activity_id', 'goods_id', 'num', 'percentage', 'max_num', 'prize_type', 'general_id', 'is_show', 'create_time'], 'integer'],
            [['cover_img', 'info', 'instructions', 'hidename', 'hidepic'], 'required'],
            [['instructions'], 'string'],
            [['hidehuiwenbi'], 'number'],
            [['cover_img', 'hidename', 'hidepic'], 'string', 'max' => 200],
            [['info'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'prize_id' => 'Prize ID',
            'activity_id' => 'Activity ID',
            'goods_id' => 'Goods ID',
            'cover_img' => 'Cover Img',
            'info' => 'Info',
            'num' => 'Num',
            'percentage' => 'Percentage',
            'max_num' => 'Max Num',
            'instructions' => 'Instructions',
            'prize_type' => 'Prize Type',
            'general_id' => 'General ID',
            'is_show' => 'Is Show',
            'hidename' => 'Hidename',
            'hidepic' => 'Hidepic',
            'hidehuiwenbi' => 'Hidehuiwenbi',
            'create_time' => 'Create Time',
        ];
    }

    public static function _getRand($proArr){
        $result = '';
        //概率数组的总概率精度
        $proSum = array_sum($proArr);
        //概率数组循环
        foreach ($proArr as $key => $proCur) {
            $randNum = mt_rand(1, $proSum);
            if ($randNum <= $proCur) {
                $result = $key;
                break;
            } else {
                $proSum -= $proCur;
            }
        }
        unset($proArr);
        return $result;
    }
}
